package com.woniuxy.sale.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.commons.annotations.RequirePermission;
import com.woniuxy.commons.result.Result;
import com.woniuxy.sale.service.AmountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@Api(tags = "结算单")
@RestController
@RequestMapping("/sale/amount")
public class AmountController {

    @Resource
    private AmountService amountService;


    /**
     * 查询所有结算单
   * */
    @RequirePermission("system")
    @GetMapping("/findAll/{pageNum}/{pageSize}")
    @ApiOperation(value = "查找所有未结算完成的打包单")
    public Result<PageInfo> findList(@PathVariable("pageNum")Integer currentPage,
                                     @PathVariable("pageSize")Integer limit){
        Result result = amountService.findStatusList(currentPage,limit);
        return result;
    }

    /**
     * 通过打包单信息id查询该单下所有的商品信息
     * */
    @RequirePermission("addPackingList")
    @GetMapping("/findPackingMsgByPackngId/{packngId}")
    @ApiOperation(value = "通过打包单id查询该单下所有的分包单信息")
    public Result findPackingMsgByPackngId(@PathVariable("packngId")String packngId){
        Map<String, Object> packingMsgByPackngId = amountService.findPackingMsgByPackngId(packngId);
        return Result.ok(packingMsgByPackngId);
    }

    @GetMapping("/findPackingMsgByPsId/{psId}")
    @ApiOperation(value = "通过分包单id查询该单下所有的商品信息")
    public Result findPackingMsgByPackngId(@PathVariable("psId") Integer psId){
        Map<String, Object> result= amountService.findPackingMsgByPsId(psId);
        return Result.ok(result);
    }

    /**
     *根据打包信息表id以及所选商品单id修改结算状态
     * */
    @RequirePermission("addPackingList")
    @PostMapping("/update")
    @ApiOperation(value = "根据所选商品单Id修改打包结算状态")
    public Result updateChooseProduceStatusByPsIdAndId(@RequestBody Map<String,Object> map){
          boolean flag = amountService.updateChooseProduceStatusByPsIdAndId(map);
            return Result.ok(flag);
    }
}
